<template>
	<!-- 我的功能模块 -->
	<view class="">
		<view class="menuBox1" v-if="menuType == 1">
			<block v-for="(item,index) in menuList" :key="index">
				<view class="menuItem1" @click="toPage(item,index)" v-if="item.isShow && item.title != '联系客服'">
					<view class="menuLine">
						<image class="menuImage" :src="item.icon" mode="widthFix"></image>
						<text>{{item.title}}</text>
					</view>
					<view v-if="item.title != '版本号'"><uni-icons type="right" size="16" color="#A1A5AA"></uni-icons></view>
					<view class="lookMore" v-else>版本号：{{headInfo.version || '1.0.0'}}</view>
				</view>
				<button class="menuItem1" open-type="contact" v-if="item.isShow && item.title == '联系客服'">
					<view class="menuLine">
						<image class="menuImage" :src="item.icon" mode="widthFix"></image>
						<text>{{item.title}}</text>
					</view>
					<view><uni-icons type="right" size="16" color="#A1A5AA"></uni-icons></view>
				</button>
			</block>
		</view>
		<view class="menuBox2" v-if="menuType == 2">
			<block v-for="(item,index) in menuList" :key="index">
				<view class="menuItem2" @click="toPage(item,index)" v-if="item.isShow && item.title != '联系客服'">
					<view class="imageBox2"><image :src="item.icon" class="image"></image></view>
					<view class="menuText2">{{item.title}}</view>
				</view>
				<button class="menuItem2" open-type="contact" v-if="item.isShow && item.title == '联系客服'">
					<view class="imageBox2"><image :src="item.icon" class="image"></image></view>
					<view class="menuText2">{{item.title}}</view>
				</button>
			</block>
			<view style="width: 25%;" v-if="length % 4 == 3"></view>
			<view style="width: 25%;" v-if="length % 4 == 2"></view>
			<view style="width: 25%;" v-if="length % 4 == 2"></view>
		</view>
		<u-popup v-model="showImage" mode="center" border-radius="14">
			<view style="width: 65vw;font-size: 0%;padding: 32rpx;background-color: #fff;padding-bottom: 16rpx;">
				<image :src="codeUrl" mode="widthFix" show-menu-by-longpress style="width: 100%;"></image>
				<view style="color:#aaa;font-size: 24rpx;height: 32rpx;display: flex;justify-content: center;align-items: center;">长按图片保存</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import { isLogin } from "../../mixins/isLogin.js"
	export default {
		name:"my-menuBox",
		mixins:[isLogin],
		props:{
			menuType:{
				type:Number,
				default:1
			},
			menuList:{
				type:Array,
				default:[]
			},
			codeUrl:{
				type:String,
				default:""
			},
		},
		created() {
			if(this.menuType == 2){
				this.length = this.menuList.filter(item =>{
					return item.isShow
				}).length
			}
		},
		data() {
			return {
				length:0,
				showImage:false
			};
		},
		methods:{
			async toPage(item,index){
				if(item.title == '协议中心' || item.title == '关于我们' || item.title == '版本号'){
					uni.navigateTo({
						url:item.url
					})
				}else if(item.title == "我的分享码"){
					let token = uni.getStorageSync('token') || 0;
					if(token){
						if(!this.codeUrl){
							uni.$u.toast("用户身份不可推荐")
						}else{
							this.showImage = true;
						}
					}else{
						this.toLogin()
					}
				}else{
					let token = uni.getStorageSync('token') || 0;
					if(token){
						uni.navigateTo({
							url:item.url
						})
					}else{
						this.toLogin()
					}
				}
			},
		}
	}
</script>

<style lang="scss">
	.menuBox1{
		.menuItem1{
			height: 88rpx;
			color: #111111 !important;
			font-size: 30rpx;
			font-weight: normal !important;
			// margin-right: 24rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.menuLine{
				font-weight: 400;
				font-size: 32rpx;
				color: #16202B;
				display: flex;
				align-items: center;
				.menuImage{
					width: 48rpx;
					height: 48rpx;
					font-size: 0;
					display: flex;
					justify-content: center;
					align-items: center;
					margin-right: 10rpx;
				}
			}
			.lookMore{
				color: #A1A5AA;
				font-size: 28rpx;
			}
		}
	}
	.menuBox2{
		display: flex;
		justify-content: space-between;
		align-items: center;
		flex-wrap: wrap;
		.menuItem2{
			width: 25%;
			margin-bottom: 24rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			.imageBox2{
				width: 90rpx;
				height: 90rpx;
				font-size: 0%;
				// background-color: #fff6f2;
				border-radius: 50%;
				// box-shadow: 0rpx 0rpx 4rpx #555;
				// margin-bottom: 8rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				.image{
					width: 70rpx;
					height: 70rpx;
				}
			}
			.menuText2{
				font-size: 26rpx;
				letter-spacing: 2rpx;
			}
		}
	}
	button::after {
	  border: none !important;
	  // padding: 0 !important;
	  // margin: 0 !important;
	}
	button {
	  background-color: transparent !important;
	  padding: 0 !important;
	  line-height: inherit !important;
	  // margin: 0 !important;
	  // width: auto !important;
	  font-weight: 400 !important;
	  border-radius: none !important;
	}
</style>